
#define DEN_CALL_TIME 300
#define MAX_RANDOM_MONSTERS 10

monster
	var/den/my_den
	var/den_spawn
	var/in_use

	death(mob/killer)
		if(den_spawn && my_den)
			my_den.remove_from(src)
		..(killer)

den
	parent_type = /monster

	den_spawn=1

	hp = 100000
	maxhp = 100000

	var
		spawn_range = 5

		list
			spawn_types = list()
			called_monsters = list()

	proc
		remove_from(monster/m)
			called_monsters -= m

		add_to(monster/m)
			called_monsters += m
			m.den_spawn = 1
			m.my_den = src

		pick_intelligent(list/l)
			for(var/turf/t in l)
				if(t.contents.len)
					l -= t

			return pick(l)

	attacked(mob/mattacker)

		if(called_monsters.len)
			for(var/monster/o in called_monsters)
				o.target(mattacker)

		else if(prob(25))
			for(var/turf/t in oview(1, src))
				if(prob(50) && !t.contents.len)
					var/x = pick(spawn_types)
					var/monster/m = new x(t)
					m.den_spawn = 1
					m.target(mattacker)

	ai()
		if(in_use) return
		in_use = 1

		spawn while(src)

			sleep(DEN_CALL_TIME)

			if(called_monsters.len >= MAX_RANDOM_MONSTERS) continue

			var/t = pick(spawn_types)
			if(t)
				add_to(new t( pick_intelligent(oview(spawn_range,src)) ))